import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2024-04-04
 * Time: 18:51
 */
public class Demo3 {
    public static int count=1;
    public static void main(String[] args) {
        BlockingQueue<Integer> queue = new ArrayBlockingQueue<>(10);
        Thread t1 = new Thread(() -> {
            while(true) {
                try {
                    queue.put(count);
                    System.out.println("t1 生产:" + count);
                    count++;


                } catch (InterruptedException e) {
                    e.printStackTrace();
                }



            }
        });
        Thread t2 = new Thread(()->{
            while(true) {


                int num = 0;
                try {
                    num = queue.take();
                    System.out.println("t2 消费:" + num);
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
        });
        t1.start();
        t2.start();
    }



}
